<!-- 考试-->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--方案数据-->
      <el-col :span="24" :xs="24">
        <el-form
          :model="searchParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="用户名称" prop="planName">
            <el-input
              v-model="searchParams.planName"
              placeholder="请输入卷名"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="openDialog(null)"
              >新增</el-button
            >
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="handleQuery"
            :columns="columns"
          ></right-toolbar>
        </el-row>

        <el-table :data="tableData" border>
          <el-table-column prop="planName" label="卷名" align="center" v-if="columns[0].visible">
          </el-table-column>
          <el-table-column prop="createType" label="组题方式" align="center" v-if="columns[1].visible">
          </el-table-column>
          <el-table-column prop="questionNum" label="总题数" align="center" v-if="columns[1].visible">
          </el-table-column>
          <el-table-column prop="passScore" label="及格分" align="center" v-if="columns[2].visible">
          </el-table-column>
          <el-table-column prop="remark" label="备注" align="center" v-if="columns[3].visible">
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间" align="center" v-if="columns[4].visible">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="200"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                @click="queryDetail(scope.row)"
                type="text"
                size="small"
                >查看</el-button
              >
              <el-button @click="openDialog(scope.row)" type="text" size="small">修改</el-button>
              <el-button @click="del(scope.row)" type="text" size="small"
                >删除</el-button
              >
              <el-button @click="pushPaper(scope.row)" type="text" size="small"
                >下发考试</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="searchParams.total > 0"
          :total="searchParams.total"
          :page.sync="searchParams.current"
          :limit.sync="searchParams.size"
          @pagination="queryPaperList"
        />
      </el-col>
    </el-row>
    <add-paper ref="AddPaperRefs"></add-paper>

    <PlanInfo ref="PlanInfoRefs"></PlanInfo>

    <AllocationQuestion ref="AllocationQuestionRefs"></AllocationQuestion>
  </div>
</template>
    
    
<script>
import { getPlanList, delPlan } from "@/api/train/index.js";
import { deptTreeSelect } from "@/api/system/user";
import AddPaper from "./components/add-paper.vue";
import PlanInfo from "./components/plan-Info.vue";
import AllocationQuestion from "./components/allocation-question.vue";
import { create } from "sortablejs";
export default {
  components: { AddPaper, PlanInfo, AllocationQuestion },
  name: "questionBank",
  data() {
    return {
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 部门名称
      deptName: undefined,
      showSearch: true,
      tableData: [],
      total: 1,
      searchParams: {
        pageNum: 1, //默认第一页
        pageSize: 10, //一页展示10条
        total: 0,
        planName: "",
        status: 1,
        orderByColumn: "create_time",
        isAsc: "desc",
      },
       // 列信息
       columns: [
        { key: 0, label: `卷名`, visible: true },
        { key: 1, label: `总题数`, visible: true },
        { key: 2, label: `及格分`, visible: true },
        { key: 3, label: `备注`, visible: true },
        { key: 4, label: `创建时间`, visible: true },
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
    };
  },
  created() {
    this.queryPaperList();
    this.getDeptTree();
  },

  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  methods: {
    handleQuery() {
      this.queryPaperList();
    },
    resetQuery() {
      this.searchParams.planName = "";
      this.searchParams.startDate = "";
      this.searchParams.endDate = "";
      this.queryPaperList();
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    del(row) {
      delPlan({
        planId: row.planId,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "删除成功",
          });
          this.queryPaperList();
        }
      });
    },
    //修改
    openEditDialog(row) {
      this.$refs.AddPaperRefs.show(); // 显示对话框
    },
    // 点击页码及上一页下一页按钮操作
    currentChange(val) {
      this.searchParams.current = val;
      //刷新表格
      this.queryPaperList();
    },
    //每页展示几条按钮操作
    sizeChange(val) {
      this.searchParams.size = val;
      //刷新表格
      this.queryPaperList();
    },
    //获取试卷列表
    queryPaperList() {
      getPlanList(this.searchParams).then((res) => {
        if (res.code === 200) {
          this.tableData = res.rows;
        }
      });
    },

    //搜索框
    searchTable() {
      this.queryPaperList();
    },

    //重置搜索框
    emptySearch() {
      searchParams.planName = "";
      searchParams.startDate = "";
      searchParams.endDate = "";
    },
    openDialog(row) {
      this.$refs.AddPaperRefs.show(row);
    },
    //下发考试
    pushPaper(row) {
      //打开下发页面
      this.$refs.AllocationQuestionRefs.show(row);
    },
    //详情
    queryDetail(row) {
      this.$refs.PlanInfoRefs.show(row.planId);
    },
  },
};
</script>>
    
<style>
.box {
  height: calc(100vh - 120px);
  font-size: 14px;
  line-height: 28px;
}

.title {
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 10px;
  padding-top: 20px;
  margin-bottom: 10px;
  border-bottom: #eee 1px dotted;
}

.tags span {
  margin-right: 10px;
}

.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.bg-purple-dark {
  background: hwb(210 95% 5%);
}

.bg-purple {
  border: 0px solid cornflowerblue;
  height: 200px;
}

.app-container {
  height: 100%;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 60px;
}
</style>
    